Ring_buffer.h
#ifndef _RING_BUFFER_H_
#define _RING_BUFFER_H_
#include "main.h"
#include <stdint.h>
/************** Defines, Type creation **************/
typedef struct
{
uint8_t* samples; // Pointer to the array (Buffer) with data to store
uint16_t buffer_size; // Total length of the Buffer
uint16_t head; // some kind of marker to store the index of the last data sample in the buffer
uint16_t tail; // some kind of marker to store the index of the next data sample after inserting elements into a buffer
uint16_t bytes_written; // Shows how many bytes we have already written into the Buffer
unsigned long samples_taken_total; // Amount of bytes written on the buffer in total (to stop writing when needed) - delete the field on constantly broadcasting devices
my_bool lock; // A flag for "locking" the Buffer for the time its being worked on. (to prewent interruptions) 1 = "locked", 0 = "unlocked"
} queue_t;
/************** Function Prototypes **************/
void init_buffer(queue_t* Buffer, uint16_t samples_amount);
uint16_t min_val(uint16_t a, uint16_t b);
my_bool put_sample(queue_t* Buffer, volatile uint8_t* data, uint8_t Size);
my_bool get_sample(queue_t* Buffer, uint8_t* data, uint8_t Size);
#endif /* _RING_BUFFER_H_ */